/**
 * 
 */
package kr.co.insoft.auth.repository.organization.impl;

import java.util.List;

import kr.co.insoft.auth.mapper.organization.OrganizationUserMapper;
import kr.co.insoft.auth.model.organization.OrganizationUserEntityModel;
import kr.co.insoft.auth.repository.organization.OrganizationUserRepository;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.RepositoryException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Repository
public class OrganizationUserRepositoryImpl implements
		OrganizationUserRepository {
	@Autowired
	OrganizationUserMapper organizationUserMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.auth.repository.organization.OrganizationUserRepository#
	 * createOrganizationUser
	 * (kr.co.insoft.auth.model.organization.OrganizationUserEntityModel)
	 */
	@Override
	public void createOrganizationUser(
			OrganizationUserEntityModel organizationUserEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(organizationUserEntityModel);
			Assert.notNull(organizationUserEntityModel.getOrgid());
			Assert.notNull(organizationUserEntityModel.getUserid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			organizationUserMapper
					.createOrganizationUser(organizationUserEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.auth.repository.organization.OrganizationUserRepository#
	 * getUserOrgs(java.lang.Long)
	 */
	@Override
	public List<OrganizationUserEntityModel> getUserOrgs(Long userid)
			throws RepositoryException {
		try {
			Assert.notNull(userid);
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return organizationUserMapper.getUserOrgs(userid);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
}
